//Iditarod Trail
//Amelia Bauer, Elise Eiden, Christine Gerardi, Taryn Green
//CSE 20212 2012
/*Set up window. Lets user change names*/
//textfield.cpp
#include <QTextFrame>
#include <iostream>
#include <stdio.h>
#include <QtGui>
#include <QLineEdit> 
#include <QPushButton>
#include <QApplication>
#include <QGridLayout>
#include <QString>
#include <QLabel>
#include <QImage>
#include <QPixmap>
#include <QMainWindow>
#include <QPalette>
#include <QHBoxLayout>
#include <QFont>
#include <string>
#include <QTimer>
#include "textfield.h"
#include "Player.h"
using namespace std;

MyTextField::MyTextField(Player *ply, QTimer * timer, QWidget *parent):QDialog(parent)
{	
	clock = timer;
	us = ply;

	QPushButton *okButton;				//make push button called ok
	okButton = new QPushButton("OK");

	//set label and texts for each variable needed
	//name
	myLabel= new QLabel (" Edit your musher's name: ", 0, 0);
	myLabel->setFont(QFont("Times New Roman", 14, QFont::Bold, true));
	myLabel-> setStyleSheet("color: darksalmon;""background-color: seashell;");
	
	mytext=new QLineEdit("Bob Bobsled");
	mytext->setFont(QFont("Times New Roman", 14));
	
	//dogs names
	myLabel2= new QLabel (" Edit your dogs' names: ", 0, 0);
	myLabel2->setFont(QFont("Times New Roman", 14, QFont::Bold, true));
	myLabel2-> setStyleSheet("color: steelblue;""background-color: mintcream;");
	
	mytext2=new QLineEdit("Matt Damon");
	mytext2->setFont(QFont("Times New Roman", 16));

	mytext3=new QLineEdit("Matt Damon");
	mytext3->setFont(QFont("Times New Roman", 16));
   
	mytext4=new QLineEdit("Matt Damon");
	mytext4->setFont(QFont("Times New Roman", 16));	

	//gender
	myLabel7=new QLabel (" Edit your gender (M/F) : ", 0 ,0);
	myLabel7->setFont(QFont("Times New Roman", 14, QFont::Bold, true));
	myLabel7-> setStyleSheet("color: darksalmon;""background-color: seashell;");
	
	mytext7=new QLineEdit("F");
	mytext7->setFont(QFont("Times New Roman", 12));	

	//space   
	space=new QLabel ("\n");
	topspace=new QLabel("                                                ");
	
	myLayout =new QGridLayout;		//make grid layout
   
	myLayout -> addWidget(topspace, 1, 1);
	myLayout -> addWidget(topspace, 1, 2); 

	myLayout -> addWidget(myLabel, 1, 3);		//displays edit line for player name
	myLayout -> addWidget(mytext, 1,4);
   
	myLayout -> addWidget(topspace, 2, 1);   //add space to move boxes to right side of screen
	myLayout -> addWidget(topspace, 2, 2);

	myLayout -> addWidget(myLabel7, 2, 3);	//displays edit line for player gender
	myLayout -> addWidget(mytext7, 2,4);
	
	myLayout -> addWidget(myLabel2,6,1);	//displays label for dog names
	
	myLayout -> addWidget(mytext2, 6,2);  //edit line for dog 1

	myLayout -> addWidget(mytext3, 6,3);  //edit line for dog2

	myLayout -> addWidget(mytext4, 6,4);  //edit line for dog3

	myLayout -> addWidget(space,3,1);    //add space
	myLayout -> addWidget(space,4,1);   //add another space
  
	myLayout -> addWidget(okButton, 7, 4);	 //displays ok button

	setLayout(myLayout);
	setWindowTitle( " Iditarod ");		//sets window title
	printScreen();
	setFixedSize(1005,640);
	
	//set fonts!
	myLabel->setFont(QFont("Times New Roman",14,QFont::Bold));	//set font for text line asking for musher name
	myLabel2->setFont(QFont("Times New Roman",14,QFont::Bold));	//text line asking user for dogs names
	myLabel7->setFont(QFont("Times New Roman",14, QFont::Bold));	//text line asking for user gender
	mytext->setFont(QFont("Times New Roman",12));			//text edit for musher name
	mytext2->setFont(QFont("Times New Roman",12));			//text edit for dog1
	mytext3->setFont(QFont("Times New Roman",12));			//dog2
	mytext4->setFont(QFont("Times New Roman",12));			//dog3
	mytext7->setFont(QFont("Times New Roman",12));			//gender

	connect (okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
	connect (mytext7, SIGNAL(textChanged(QString)), this, SLOT(checkGender()));

}

void MyTextField::okClicked()		// when ok is pressed, each variable entered is displayed in terminal
{
	us->setName(mytext-> text().toStdString());
	if(mytext7->text().toStdString()=="F" || mytext7->text().toStdString() =="f")
	{
		us->setGender(1);
	}
	else if(mytext7-> text().toStdString()=="M" || mytext7-> text().toStdString() =="m")
	{
		us->setGender(0);
	}
	us->setNameDogs(0, mytext2->text().toStdString());
	us->setNameDogs(1, mytext3->text().toStdString());
	us->setNameDogs(2, mytext4->text().toStdString());
	clock->start(1000);
	this->hide();
}

void MyTextField::printScreen()	//sets background image to snowy scene with lodge, player and dogs
{
	QPalette palette;
	palette.setBrush(this->backgroundRole(), QBrush(QImage("BackgroundOpen2.jpg")));
	this->setPalette(palette);	//use this pointer to set background picture
}
void MyTextField::checkGender()
{
	if(mytext7->text().toStdString()!= "F" && mytext7->text().toStdString()!= "f" && mytext7->text().toStdString()!= "M" && mytext7->text().toStdString()!= "m")
	{
		mytext7->setText(QString("F"));
		us->setGender(1);
	}
}

